package util;

import java.io.IOException;

import org.apache.log4j.Appender;
//import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;

public class Debug {
	private static int i = 1;
	private static String logFilePath = "D://log.txt";
	private static Logger logger = Logger.getLogger(Debug.class);
	
	//init
	static {
		//BasicConfigurator.configure();
		Appender consoleLog = new ConsoleAppender(new SimpleLayout());
		logger.addAppender(consoleLog); //xuat log ra console
		
		try {
			Appender logFile = new FileAppender(new SimpleLayout(), logFilePath);
			logger.addAppender(logFile); //xuat log ra file
		} catch (IOException e) {
			logger.error("Cannot create the log file!!!");
		}
		
		logger.info("---LOG INFORMATION---"); //once!
	}
	
	public static void log(Object clazz, String method, String message) {
		logger.debug(i++ + ")" + clazz.getClass().getName() + "> " + method + "> " + message);
	}
	
	public static void log(String msg) {
		logger.debug(i++ + ")" + msg);
	}
	
	public static void main(String[] args) {
		log(new Debug(), "main", "test");
	}
}
